$(document).ready(function()
{
	$(".userAdminPermissionsAll").click(function(){
		var gid = $(this).attr("gid");
		$("#userAdminPermissionsForm .groupPermission_"+gid).attr("checked","checked");
		return false;
	});
	$(".userAdminPermissionsNone").click(function(){
		var gid = $(this).attr("gid");
		$("#userAdminPermissionsForm .groupPermission_"+gid).attr("checked","");
		return false;
	});
	
	// shorten names

	$("table.admin-permissions").each(function(){
		var i = 0;
		$(this).find("thead th").each(function(){
			if(i>0){
				var text = $(this).text();
				$(this).attr("title", text);
				$(this).css({width: "50px"});
			}
			i++;
		});
	});
});



function savePermissions(form){
    var send = "";
    var i=0;
	while (i >= 0) {
	    if(!form[i]){
            break;
        }
        if(form[i].name && form[i].value && form[i].checked){
        
            send += form[i].name + "="+1+"&";
        }
		i++;
	}
    Cyfy.ajax("Users", "savePermissions", "", send);
}
